package com.hrt;

import com.hrt.mapper.EmpMapper;
import com.hrt.pojo.Emp;
import com.hrt.pojo.EmpOneOne;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Auther: hrt
 * @Date: 2022/3/8
 * 一对一 一对多 多对多测试
 */
public class EmpOneManyTest {
    private SqlSession sqlSession;
    @Before
    public void init(){
        SqlSessionFactoryBuilder ssfb =new SqlSessionFactoryBuilder();
        InputStream resourceAsStream = null;
        try {
            resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory factory=ssfb.build(resourceAsStream) ;
        sqlSession=factory.openSession(true);
    }

    /**
     * 测试一对一
     */
    @Test
    public void one2oneTest(){
        EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
        EmpOneOne emp = mapper.findEmpJoinDeptByEmpno(7369);
        System.out.println(emp);
    }
}
